<template>
  <div class="login">
    <div class="login-box">
      <img src="@/assets/login/login-l.png" alt="" />
      <div class="login-form">
        <el-form :model="loginForm">
          <div class="login-form-title">
            <img src="@/assets/login/icon_logo.png" alt="" />
          </div>
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" prefix-icon="user">
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" prefix-icon="lock">
            </el-input> 
          </el-form-item>
          <el-form-item style="width: 100%">
            <el-button class="login-btn" type="primary" style="width: 100%">
              登录
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>


<script lang="ts" setup>
import { reactive,ref} from 'vue';



  // 定义一个验证用户名的函数
 const validateUserName = (rule: any, value: string, callback: Function) => {
  // 检查用户名是否为空
  if (!value) {
    // 如果用户名为空，调用 callback 函数并传入一个错误对象，提示用户输入用户名
    callback(new Error('请输入用户名'));
  } else {
    // 如果用户名不为空，调用 callback 函数而不传入任何参数，表示验证通过
    callback();
  }
}

  // 定义一个验证密码的函数
  const validatePassword = (rule: any, value: string, callback: Function) => {
    // 检查用户名是否为空
    if (value.length < 6) {
      callback(new Error('密码必须在6位以上'))
    } else {
      // 如果密码不为空，调用 callback 函数而不传入任何参数，表示验证通过
      callback()
    }
  }

  //定义表单数据
  const loginForm = reactive({
    username: 'admin',
    password: '123456'
  })

  // 定义表单验证规则
  const loginRules = {
    username: [{ validator: validateUserName, trigger: 'blur' }],
    password: [{ validator: validatePassword, trigger: 'blur' }],
  }

</script>

<style lang="scss">
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
  // background: #476dbe;
  background-color: #333;
}

.login-box {
  width: 1000px;
  height: 474.38px;
  border-radius: 8px;
  display: flex;

  img {
    width: 60%;
    height: auto;
  }
}

.login-form {
  background: #ffffff;
  width: 40%;
  border-radius: 0px 8px 8px 0px;
  display: flex;
  justify-content: center;
  align-items: center;

  .el-form {
    width: 214px;
    height: 307px;
  }

  .el-form-item {
    margin-bottom: 30px;
  }

  .el-form-item.is-error .el-input__inner {
    border: 0 !important;
    border-bottom: 1px solid #fd7065 !important;
    background: #fff !important;
  }

  .input-icon {
    height: 32px;
    width: 18px;
    margin-left: -2px;
  }

  .el-input__inner {
    border: 0;
    border-bottom: 1px solid #e9e9e8;
    border-radius: 0;
    font-size: 12px;
    font-weight: 400;
    color: #333333;
    height: 32px;
    line-height: 32px;
  }

  .el-input__prefix {
    left: 0;
  }

  .el-input--prefix .el-input__inner {
    padding-left: 26px;
  }

  .el-input__inner::placeholder {
    color: #aeb5c4;
  }

  .el-form-item--medium .el-form-item__content {
    line-height: 32px;
  }

  .el-input--medium .el-input__icon {
    line-height: 32px;
  }
}

.login-btn {
  border-radius: 17px;
  padding: 11px 20px !important;
  margin-top: 10px;
  font-weight: 500;
  font-size: 12px;
  border: 0;
  font-weight: 500;
  color: #333333;
  // background: #09a57a;
  background-color: #ffc200;

  &:hover,
  &:focus {
    // background: #09a57a;
    background-color: #ffc200;
    color: #ffffff;
  }
}

.login-form-title {
  height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 40px;

  .title-label {
    font-weight: 500;
    font-size: 20px;
    color: #333333;
    margin-left: 10px;
  }
}
</style>
